﻿using Galoap;
using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Transactions;

namespace Tests
{
    /// <summary>
    /// Summary description for UserTest
    /// </summary>
    [TestClass]
    public class UserTest
    {
        public UserTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        //[ExpectedException(typeof(ArgumentException))]
        public void UserRegisterTest()
        {
            /*User.Register(new User { Name = "Simon", LastName = "Krige", NickName = "Sk", Email = "sk@eth.ch", Password = "pass" });
            User.Register(new User { Name = "Simon", LastName = "Krige", NickName = "Sk", Email = "sk@eth.ch", Password = "pass" });
            Assert.Fail();*/

        }

        [TestMethod]
        public void UserLoginTest()
        {
            /*User.Register(new User { Name = "Simon", LastName = "Krige", NickName = "simonk", Email = "sk1@eth.ch", Password = "pass" });
            Assert.AreEqual("Simon", User.Login("simonk", "pass").Name);*/

        }

        [TestMethod]
        public void MostPlayedGameTest()
        {
            User user = User.GetUserByNickname("einstein");
            Assert.AreEqual("Tontolone", user.GetMostPlayedGame().Title);
        }

        [TestMethod]
        public void UserRequestsByNickNameTest()
        {
            Assert.AreEqual("Albert", User.GetUserByNickname("einstein").Name);
        }

        [TestMethod]
        public void GetLastScoreTest()
        {
            User user = User.GetUserByNickname("einstein");
            int score = user.GetLastScore();
            Assert.AreEqual(1000, score);
        }

        [TestMethod]
        public void GetLastLevelTest()
        {
            User user = User.GetUserByNickname("einstein");
            int level = user.GetLastLevel();
            Assert.AreEqual(1, level);
        }

        /// <summary>
        ///A test for GetUserWithHighestRanking
        ///</summary>
        [TestMethod()]
        public void GetUserWithHighestRankingTest()
        {
            User actual = User.GetUserWithHighestRanking(Game.GetGame(1));
            Assert.AreEqual(2, actual.UserID);
        }

        /// <summary>
        ///A test for GetAllUsers
        ///</summary>
        [TestMethod()]
        public void GetAllUsersTest()
        {  
            List<User> actual = User.GetAllUsers();
            Assert.AreEqual(4, actual.Count);
        }

        /// <summary>
        ///A test for GetGamesPlayedCount
        ///</summary>
        [TestMethod()]
        public void GetGamesPlayedCountTest()
        {
            int actual = User.GetUserByNickname("einstein").GetGamesPlayedCount();
            Assert.AreEqual(3, actual);
        }

        /// <summary>
        ///A test for GetLastGame
        ///</summary>
        [TestMethod()]
        public void GetLastGameTest()
        {
            Game actual = User.GetUserByNickname("einstein").GetLastGame();
            Assert.AreEqual("Tontolone", actual.Title);
        }

        /// <summary>
        ///A test for GetLastKSessions
        ///</summary>
        [TestMethod()]
        public void GetLastKSessionsTest()
        {
            List<GameSession> actual = User.GetUserByNickname("einstein").GetLastKGameSessions(1);
            Assert.AreEqual(1, actual.Count);
        }

        /// <summary>
        ///A test for GetMostFrequentlyPlayedGame
        ///</summary>
        [TestMethod()]
        public void GetMostFrequentlyPlayedGameTest()
        {
            Game actual = User.GetUserByNickname("einstein").GetMostFrequentlyPlayedGame();
            Assert.AreEqual("Tontolone", actual.Title);
        }

        /// <summary>
        ///A test for GetMostPlayedGame
        ///</summary>
        [TestMethod()]
        public void GetMostPlayedGameTest()
        {
            Game actual = User.GetUserByNickname("einstein").GetMostPlayedGame();
            Assert.AreEqual("Tontolone", actual.Title);
        }

        /// <summary>
        ///A test for GetRankingForGame
        ///</summary>
        [TestMethod()]
        public void GetRankingForGameTest()
        {
            double actual = User.GetUserByNickname("einstein").GetRankingForGame(Game.GetGame(1));
            Assert.AreEqual(0.9, actual);
        }

        /// <summary>
        ///A test for GetSessionsCount
        ///</summary>
        [TestMethod()]
        public void GetSessionsCountTest()
        {
            int actual = User.GetUserByNickname("einstein").GetGameSessionsCount();
            Assert.AreEqual(3, actual);
        }

        /// <summary>
        ///A test for GetUserByID
        ///</summary>
        [TestMethod()]
        public void GetUserByIDTest()
        {
            User actual = User.GetUserByID(2);
            Assert.AreEqual("einstein", actual.NickName);
        }

        /// <summary>
        ///A test for GetUserWithLowestRanking
        ///</summary>
        [TestMethod()]
        public void GetUserWithLowestRankingTest()
        {
            User actual = User.GetUserWithLowestRanking(Game.GetGame(1));
            Assert.AreEqual(User.GetUserByNickname("stallaman").UserID, actual.UserID);
        }
    }
}
